import { defineStore } from "pinia";
import { Message } from "@arco-design/web-vue";
import * as fileApi from "@/api/file";

export const useFileStore = defineStore("file", () => {
  async function getFileList(param?: any) {
    const response = await fileApi.getFileList(param);
    if (response.code === 20000) {
      return response.data.files;
    }
    return [];
  }

  async function saveFile(param?: any) {
    const response = await fileApi.createFile({ ...param });
    if (response.code === 20000) {
      Message.success("更新成功");
    }
  }

  async function deleteFile(param?: any) {
    const response = await fileApi.deleteFile(param);
    if (response.code === 20000) {
      Message.success("移除成功");
    }
  }

  return { getFileList, saveFile, deleteFile };
});
